﻿using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.ValueGeneration;

namespace DX.DbStorage.EF
{
    public class AppNameGenerator : ValueGenerator<string>
    {
        public override bool GeneratesTemporaryValues => false;

        public override string Next(EntityEntry entry)
        {
            var provider = entry.Context.GetService<IAppProvider>();
            if (provider != null)
            {
                return provider.GetName();
            }
            return System.Reflection.Assembly.GetEntryAssembly().GetName().Name;
        }
    }


}
